import axios from 'axios';

const BASE_URL = 'http://localhost:8080/Airliners';

//查询所有客机
export const listAirliners = async () => {
    try {
        const response = await axios.get(BASE_URL);
        return response.data;
    } catch (error) {
        console.error('Error listing flights:', error.response ? error.response.data : error.message);
        throw error;
    }
};

// 更新客机状态
export const updateAirliner = async (airliner) => {
    try {
        const response = await axios.put(BASE_URL, airliner, {
            headers: {
                'Content-Type': 'application/json'
            }
        });
        return response.data;
    } catch (error) {
        console.error('Error updating room:', error.response ? error.response.data : error.message);
        throw error;
    }
};

//删除客机
export const deleteAirliner = async (id) => {
    try {
        const response = await axios.delete(`${BASE_URL}/${id}`);
        return response.data;
    } catch (error) {
        console.error('Error listing flights:', error.response ? error.response.data : error.message);
        throw error;
    }
};

//增加客机
export const addAirliner = async (airliner) => {
    try {
        const response = await axios.post(BASE_URL,airliner);
        return response.data;
    } catch (error) {
        console.error('Error listing airliners:', error.response ? error.response.data : error.message);
        throw error;
    }
};


